//
//  PageCache.hpp
//  高并发内存池
//
//  Created by 卜绎皓 on 2023/2/14.
//

#ifndef PageCache_hpp
#define PageCache_hpp

#endif /* PageCache_hpp */

#pragma once

#include "Common.hpp"
//单例模式
class PageCache
{
public:
    //提供一个全局访问点
    static PageCache* GetInstance()
    {
        return &_sInst;
    }
    
    //获取从对象到span的映射
    Span* MapObjectToSpan(void* obj);
    
    //
    void ReleaseSpanToPageCache(Span* span);
    
    Span* NewSpan(size_t k);

    std::mutex _pageMtx;
    
private:
    SpanList _spanLists[NPAGES];
    
    std::unordered_map<PAGE_ID,Span*> _idSpanMap;
    
    PageCache()
    {
        
    }
    PageCache(const PageCache&) = delete;
    
    static PageCache _sInst;
};
